<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form>
        <a-form-item :labelCol="labelCol" :wrapperCol="labelCol" label="订单编号">
          <a-input disabled v-model="templateOrderId" />
        </a-form-item>
        <!-- <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="订单退款理由">
          <a-textarea v-model="templateReason"  />
        </a-form-item> -->
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="退款金额">
          <a-input-number
            style="width: 200px"
            placeholder="请输入退款金额单位（元），例：一分钱，输入：0.01"
            :formatter="(value) => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
            :min="0"
            v-model="refundData"
            :precision="2"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { Slime } from '@/mixins/slime';
import { evaFiltersMixin } from '@/mixins/evaMixin';
import ApiTree from '@/api/order/orderList';

export default {
  name: 'OrderModel',
  mixins: [Slime, evaFiltersMixin],
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      url: {
        send: '/mall/order/doRefund',
      },
      templateOrderId: '',
      // templateReason:'',
      //
      refundData: '',
    }
  },
  methods: {
    open(record) {
      this.templateOrderId = record.id
      this.refundData = (record.money/100).toFixed(2)
      this.visible = true
    },
    close() {
      this.templateOrderId = ''
      // this.templateReason = ''
      this.refundData = ''
      this.visible = false;
      this.$emit("closeModal")
    },
    handleOk() {
      let that = this;
      // if(this.templateReason.length > 90){
      //   this.$message.warning('备注的字数过长')
      //   return false
      // }
      this.confirmLoading = true
      let param = {
        orderId: this.templateOrderId,
        money: Math.round(this.refundData * 100),
      }
      that.loading = true;
      ApiTree.getDetailRefund(param).then((res) => {
        if (res.code == 0) {
          that.$message.success('退款成功');
        } else {
          that.$message.warning(res.message)
        }
      })
      .finally(() => {
        that.loading = false;
        that.confirmLoading = false;
        that.close();
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>